<!DOCTYPE html>
<html lang="en">
<html lang="en" xmlns:th="http://wwww.thymeleaf.org" >
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="../aaa/css/font.css">
    <link rel="stylesheet" href="../aaa/css/xadmin.css">
    <!--<script src="../aaa/lib/layui/layui.js" charset="utf-8"></script>-->
    <script type="text/javascript" src="../aaa/js/xadmin.js"></script>
    <script type="text/javascript" src="../aaa/lib/layui/layui.js" charset="utf-8"></script>
    <script src="../aaa/js/jquery-3.1.1.js"></script>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
</head>
<script>
    layui.use('form', function(){
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        form.render();
    });
</script>
<body>
<!--id：<input type="text" id="inp1" /><br>-->
<div class="layui-row">
    <br>

    <div class="layui-form-item">
        <label  class="layui-form-label">
            <span class="x-red">*</span>分销需求id:
        </label>
        <div class="layui-input-inline">
            <input type="text" id="inp15" name="dis_need_id" required="" lay-verify="required"
                   autocomplete="off" class="layui-input">
        </div>
        <label class="layui-form-label">分销商:</label>
        <div class="layui-input-inline layui-form" >
            <select  name="distributors" class="layui-input" id="inp1" lay-verify="required" >
                <option value="">请选择分销商</option>
                <option th:each="distributors:${distributors}"
                        th:value="${distributors.distributorid}"
                        th:text="${distributors.distributorname}"
                ></option>
            </select>
        </div>
        <label class="layui-form-label">供应商:</label>
        <div class="layui-input-inline layui-form" >
            <select  name="dept_id" class="layui-input" id="inp2" lay-verify="required">
                <option value="">请选择商品供应商</option>
                <option th:each="suppliers:${suppliers}"
                        th:value="${suppliers.supId}"
                        th:text="${suppliers.supName}"
                ></option>
            </select>
        </div>

    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">商品详情:</label>
        <div class="layui-input-inline layui-form" >
            <select  name="dept_id" class="layui-input" id="inp3">
                <option value="">请选择商品</option>
                <option th:each="commodities:${commodities}"
                        th:value="${commodities.commodityid}"
                        th:text="${commodities.commodityname}"
                ></option>
            </select>
        </div>
        <label class="layui-form-label">包装类型:</label>
        <div class="layui-input-inline layui-form" >
            <select  name="dept_id" class="layui-input" id="inp4">
                <option value="">请选择包装类型</option>
                <option th:each="bcategory:${bcategory}"
                        th:value="${bcategory.Bcategoryid}"
                        th:text="${bcategory.Bcategoryname}"
                ></option>
            </select>
        </div>
        <label class="layui-form-label">包装供应商:</label>
        <div class="layui-input-inline layui-form" >
            <select  name="dept_id" class="layui-input" id="inp5">
                <option value="">请选择包装供应商</option>
                <option th:each="bsuppliers:${bsuppliers}"
                        th:value="${bsuppliers.BsupId}"
                        th:text="${bsuppliers.BsupName}"
                ></option>
            </select>
        </div>

    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">物流公司:</label>
        <div class="layui-input-inline layui-form" >
            <select  name="dept_id" class="layui-input" id="inp6">
                <option value="">请选择物流公司</option>
                <option th:each="logistics:${logistics}"
                        th:value="${logistics.logId}"
                        th:text="${logistics.logname}"
                ></option>
            </select>
        </div>
        <label class="layui-form-label">物流方式:</label>
        <div class="layui-input-inline layui-form" >
            <select  name="dept_id" class="layui-input" id="inp7">
                <option value="">请选择运输方式</option>
                <option th:each="logmodes:${logmodes}"
                        th:value="${logmodes.logmodeid}"
                        th:text="${logmodes.logmodename}"
                ></option>
            </select>
        </div>
        <label class="layui-form-label">审核状态:</label>
        <div class="layui-input-inline layui-form" >
            <select  name="dept_id" class="layui-input" id="inp8">
                <option value="1">未审核</option>
            </select>
        </div>

    </div>

    <div class="layui-form-item">
        <label  class="layui-form-label">
            <span class="x-red">*</span>定金：
        </label>
        <div class="layui-input-inline">
            <input type="text" id="inp9" required="" lay-verify="required"
                   autocomplete="off" class="layui-input" />
        </div>
        <label  class="layui-form-label">
            <span class="x-red">*</span>商品数量：
        </label>
        <div class="layui-input-inline">
            <input type="text" id="inp10" required="" lay-verify="required"
                   autocomplete="off" class="layui-input" />
        </div>
        <label  class="layui-form-label">
            <span class="x-red">*</span>包装数量：
        </label>
        <div class="layui-input-inline">
            <input type="text" id="inp11" required="" lay-verify="required"
                   autocomplete="off" class="layui-input" />
        </div>

    </div>
            <div class="layui-form-item">
                <label  class="layui-form-label">
                    <span class="x-red">*</span>日期：
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="inp12" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" />
                </div>
                <label  class="layui-form-label">
                    <span class="x-red">*</span>物流单号：
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="inp13" required="" lay-verify="required"
                           autocomplete="off" class="layui-input"  name="logparticularsid"/>
                </div>
                <label class="layui-form-label">样板包装:</label>
                <div class="layui-input-inline layui-form" >
                    <select  name="dept_id" class="layui-input" id="inp14">
                        <option value="">请选择样板包装</option>
                        <option th:each="need:${needs}"
                                th:value="${need.needId}"
                                th:text="${need.needName}"
                        ></option>
                    </select>
                </div>
            </div>
    <button  class="layui-btn" lay-filter="add" value="添加一行" onclick="addNode()" lay-submit="">添加</button>
</div>
<table cellpadding="0" cellspacing="0" border="0" id="data1" class="layui-table layui-form">
    <tbody id="tbody">
    <thead>
    <th style="display: none">分销需求id</th>
    <th>分销商</th>
    <th style="display: none">商品供应商</th>
    <th>商品详情</th>
    <th>包装类型</th>
    <th>包装供应商</th>
    <th style="display: none">物流公司</th>
    <th style="display: none">运输方式</th>
    <th style="display: none">审核状态</th>
    <th>定金</th>
    <th style="display: none">商品数量</th>
    <th style="display: none">包装数量</th>
    <th>日期</th>
    <th>物流单号</th>
    <th>样板包装</th>
    <th>操作</th>
    </thead>
    <tbody>
</table>
<br/><br/>
<button class="layui-btn"  onclick="f()">提交</button>
</body>
<script src="../aaa/js/jquery-3.1.1.js"></script>
<script>
    //批量添加
    function f() {
        var data1 = Array();
        var data2 = Array();
        var data3 = Array();
        var data4 = Array();
        var data5 = Array();
        var data6 = Array();
        var data7 = Array();
        var data8 = Array();
        var data9 = Array();
        var data10 = Array();
        var data11 = Array();
        var data12 = Array();
        var data13 = Array();
        var data14 = Array();
        var data15 = Array();
        var bsuppliers = Array();
        $("span[name='distributorid']").each(function(){
            data1.push($(this).text())
        });
        $("span[name='supId']").each(function(){
            data2.push($(this).text())
        });
        $("span[name='commodityid']").each(function(){
            data3.push($(this).text())
        });
        $("span[name='Bcategoryid']").each(function(){
            data4.push($(this).text())
        });
        $("span[name='BsupId']").each(function(){
            data5.push($(this).text())
        });
        $("span[name='logId']").each(function(){
            data6.push($(this).text())
        });
        $("span[name='logmodeid']").each(function(){
            data7.push($(this).text())
        });
        $("span[name='statusid']").each(function(){
            data8.push($(this).text())
        });
        $("span[name='advance']").each(function(){
            data9.push($(this).text())
        });
        $("span[name='Samnumber']").each(function(){
            data10.push($(this).text())
        });
        $("span[name='satypenumber']").each(function(){
            data11.push($(this).text())
        });
        $("span[name='birth']").each(function(){
            data12.push($(this).text())
        });
        $("span[name='logparticularsid']").each(function(){
            data13.push($(this).text())
        });
        $("span[name='dis_need_id']").each(function(){
            data15.push($(this).text())
        });

        $("span[name='needId']").each(function(){
            data14.push($(this).text())
        });
        var i = 0;
        $("span[name='needId']").each(function() {
                bsuppliers.push({
                    distributorid: data1[i],
                    supId: data2[i],
                    commodityid: data3[i],
                    Bcategoryid: data4[i],
                    BsupId: data5[i],
                    logId: data6[i],
                    logmodeid: data7[i],
                    statusid: data8[i],
                    advance: data9[i],
                    Samnumber: data10[i],
                    satypenumber: data11[i],
                    birth: data12[i],
                    logparticularsid: data13[i],
                    dis_need_id: data15[i],
                    needId: $(this).text()
                }); i++
            }
        );
        $.ajax({
            type: "post",
            url: "/dis_need/addpiliang?logparticularsid="+data13+"&logId="+data6+"&advance="+data9,
            dataType: 'json',
            contentType: "application/json",
            data: JSON.stringify(bsuppliers),
            success: function () {

            }
        });

        layer.msg("添加成功",{
            icon: 6,
            time:500
        },function() {
            parent.window.location.reload();//重新页面
            // 获得frame索引
            var index = parent.layer.getFrameIndex(window.name);
            //关闭当前frame
            parent.layer.close(index);
        });
    }

    function addNode(){
        var inp1 = $("#inp1").val();
        var inp2 = $("#inp2").val();
        var inp3 = $("#inp3").val();
        var inp4 = $("#inp4").val();
        var inp5 = $("#inp5").val();
        var inp6 = $("#inp6").val();
        var inp7 = $("#inp7").val();
        var inp8 = $("#inp8").val();
        var inp9 = $("#inp9").val();
        var inp10 = $("#inp10").val();
        var inp11 = $("#inp11").val();
        var inp12 = $("#inp12").val();
        var inp13 = $("#inp13").val();
        var inp14 = $("#inp14").val();
        var inp15 = $("#inp15").val();
        if (inp1=="" || inp2=="" || inp3=="" || inp4=="" || inp5=="" || inp6=="" || inp7=="" || inp8=="" ||
            inp9=="" || inp10=="" || inp11=="" || inp12==""  || inp13=="" ||inp14=="" ||inp15=="" ) {
            alert("不能为空")
        }else {
            var tr = "<tr>";
            tr = tr + "<td><span name='distributorid'>" + inp1 + "</span></td>";
            tr = tr + "<td style='display: none'><span name='supId'>" + inp2 + "</span></td>";
            tr = tr + "<td><span name='commodityid'>" + inp3 + "</span></td>";
            tr = tr + "<td><span name='Bcategoryid'>" + inp4 + "</span></td>";
            tr = tr + "<td><span name='BsupId'>" + inp5 + "</span></td>";
            tr = tr + "<td style='display: none'><span name='logId'>" + inp6 + "</span></td>";
            tr = tr + "<td style='display: none'><span name='logmodeid'>" + inp7 + "</span></td>";
            tr = tr + "<td style='display: none'><span name='statusid'>" + inp8 + "</span></td>";
            tr = tr + "<td><span name='advance'>" + inp9 + "</span></td>";
            tr = tr + "<td style='display: none'><span name='Samnumber'>" + inp10 + "</span></td>";
            tr = tr + "<td style='display: none'><span name='satypenumber'>" + inp11 + "</span></td>";
            tr = tr + "<td><span name='birth'>" + inp12 + "</span></td>";
            tr = tr + "<td><span name='logparticularsid'>" + inp13 + "</span></td>";
            tr = tr + "<td><span name='needId'>" + inp14 + "</span></td>";
            tr = tr + "<td style='display: none'><span name='dis_need_id'>" + inp15 + "</span></td>";
            tr = tr + "<td><button onclick='deleteNode(this)'>删除</button></td>";
            tr = tr + "</tr>";
            $("#tbody").append(tr);
            $(function() {
                //（YB + 年月日 + 四位随机数）
                var myDate = new Date;
                var year = myDate.getFullYear(); //获取当前年
                var mon = myDate.getMonth() + 1; //获取当前月
                // var date = myDate.getDate(); //获取当前日
                // if (date<10){
                //     date = "0"+date;
                // }
                var x = 99;
                var y = 999;
                var rand = parseInt(Math.random()*(x-y+1)+y);
                $("input[name='logparticularsid']").val("WL"+year+""+mon+""+""+rand);
                $("input[name='dis_need_id']").val("XQ"+year+""+mon+""+""+rand);

                // $("input[name='date_of_order']").val(year+"-"+mon+"-"+date);
            });
        }
    }
    function deleteNode(){
        $("tr:last").remove();
    }
    function deleteNode(obj){
        $(obj).parent().parent().remove();
    }

    function add(obj){
        var num = $(obj).prev().html();//紧挨着的上一个标签
        num++;
        if(num>0){
            $(".reduce").removeProp("disabled");
        }
        var price =Number($(obj).parent().parent().children().eq(2).html())*Number(num)+Number($(obj).parent().parent().children().eq(3).html());//取总价格
        $(obj).parent().parent().children().eq(4).html(price);//给总计那列赋值
        $(obj).prev().html(num);
        zPrice();//调用总价钱的函数
    }
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#inp12',
            trigger: 'click'//指定元素
        });
    });

    $(function() {
        //（YB + 年月日 + 四位随机数）
        var myDate = new Date;
        var year = myDate.getFullYear(); //获取当前年
        var mon = myDate.getMonth() + 1; //获取当前月
        // var date = myDate.getDate(); //获取当前日
        // if (date<10){
        //     date = "0"+date;
        // }
        var x = 99;
        var y = 999;
        var rand = parseInt(Math.random()*(x-y+1)+y);
        $("input[name='logparticularsid']").val("WL"+year+""+mon+""+""+rand);
        $("input[name='dis_need_id']").val("XQ"+year+""+mon+""+""+rand);

        // $("input[name='date_of_order']").val(year+"-"+mon+"-"+date);
    });
</script>
</html>
